﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace jSLCore.Client.Presentation.BaseControl.Validation
{
    public partial class OkCancelControl : UserControl
    {
        public OkCancelControl()
        {
            InitializeComponent();
        }

        #region ErrorBox
        public BaseControl BaseControl
        {
            get { return errorBox.BaseControl; }
            set
            {
                errorBox.BaseControl = value;
            }
        }

        public string BaseControlName
        {
            get { return errorBox.BaseControlName; }
            set { errorBox.BaseControlName = value; }
        }

        public string BindingGroupName
        {
            get { return errorBox.BindingGroupName; }
            set { errorBox.BindingGroupName = value; }
        } 
        #endregion
        
        #region OkCancel Event Delegating
        private void dialogOk_Clicked(object sender, RoutedEventArgs e)
        {
            InvokeOkClicked(EventArgs.Empty);
        }

        private void dialogCancel_Clicked(object sender, RoutedEventArgs e)
        {
            InvokeCancelClicked(EventArgs.Empty);
        }


        public event EventHandler OkClicked;

        private void InvokeOkClicked(EventArgs e)
        {
            EventHandler clicked = OkClicked;
            if (clicked != null) clicked(this, e);
        }

        public event EventHandler CancelClicked;

        void InvokeCancelClicked(EventArgs e)
        {
            EventHandler clicked = CancelClicked;
            if (clicked != null) clicked(this, e);
        } 
        #endregion

        #region okCancel Delegating
        public object OkContent
        {
            get { return okButton.Content; }
            set { okButton.Content = value; }
        }

        public object CancelContent
        {
            get { return cancelButton.Content; }
            set { cancelButton.Content = value; }
        }

        public bool OkIsEnabled
        {
            get { return okButton.IsEnabled; }
            set { okButton.IsEnabled = value; }
        }

        public bool OkIsVisible
        {
            get { return okButton.Visibility == Visibility.Visible; }
            set { okButton.Visibility = value ? Visibility.Visible : Visibility.Collapsed; }
        }

        public bool CancelIsVisible
        {
            get { return cancelButton.Visibility == Visibility.Visible; }
            set { cancelButton.Visibility = value ? Visibility.Visible : Visibility.Collapsed; }
        } 
        #endregion
    }
}
